package com.hoku.account.client;

import com.hoku.account.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * feign client 客户端(接口调用端)负载均衡
 * 调用auth-service的client
 * @author ZHUFEIFEI
 */
@FeignClient(name="${services.auth-service-id}", fallback = AuthClientFallBack.class)
public interface IAuthClient {
    /**
     * create user
     * @param user
     */
    @PostMapping(path = "/uaa/user")
    void createUser(User user);
}

/**
 * Component注解必须加，client会根据fallback信息查找对应的bean
 * FeignClient-fallback注释
 */
@Slf4j
@Component
class AuthClientFallBack implements IAuthClient {

    @Override
    public void createUser(User user) {
        log.error("feign create user failed : {}", user.getUsername());
    }
}
